<?php
/**
 * 获取H5支付链接
 *
 */
include './PayTool.php';

$tool = new PayTool();
$params = initParams($tool);

$result = $tool->getResultWithUrl($tool->req_url, $params);
echo 'Req Data:'.$result.'</br>';

if($tool->checkResult($result,$tool)){
    $object = json_decode($result);
    if ($tool->resultSuccess($object)) {
        echo  'Req Data: '.$result.'</br>';
    } else {
        echo 'msg : '.$object->msg;
    }
}else{
    echo '<br>验签失败';
}


function initParams($tool){
    $merchant=$tool->merchantId;
    $sn = $tool->getSN($merchant);
//    请根据实际情况转码为 UTF-8
//    $subject = iconv('GB2312','UTF-8','****');
//    $params['subject'] = $subject;

    $params = array();
    $params['sn'] = $sn;
    $params['merchant'] = $merchant;
    $params['totalAmount'] = '10.67';
    $params['subject'] = '通用测试';
    $params['callBack'] = $tool->callBack_url;
    $params['channel'] = 'weixin';
    $params['busiType'] = '160001';
    $params['remark'] = '特惠商品';
    $params['authCode'] = '134766101736617986';//微信授权码
    $params['version'] = '2.0';

    $sign = $tool->sign($params, $tool->pay_key);
    $params['sign']= $sign;
    return $params;

}


?>